from OCC.Core.BRepBuilderAPI import  BRepBuilderAPI_MakeFace
from OCC.Display.OCCViewer import rgb_color
from OCC.Display.SimpleGui import init_display
from OCC.Core.GEOMAlgo import GEOMAlgo_Splitter
from OCC.Core.gp import gp_Dir, gp_Pln, gp_Pnt
from OCC.Extend.TopologyUtils import TopologyExplorer

display, start_display, add_menu, add_function_to_menu = init_display()

# 第一个面
p0 = gp_Pnt(5,5,5,)
vnorm = gp_Dir(1, 1, 1)
pln = gp_Pln(p0, vnorm)
face1 = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
# 工具面
p0 = gp_Pnt(5,5,5,)
vnorm = gp_Dir(1, 1, 0)
pln = gp_Pln(p0, vnorm)
face2 = BRepBuilderAPI_MakeFace(pln, -20, 20, -20, 20).Face()

# 启动分割函数
splitter = GEOMAlgo_Splitter()
# 将face1作为参数，将面face2作为分割工具。
splitter.AddArgument(face1)
splitter.AddTool(face2)
splitter.Perform()

#  显示分割后的face
for shape in TopologyExplorer(splitter.Shape()).faces():
    display.DisplayShape(shape,update=True)

#  显示使用的工具：面
display.DisplayShape(face2,update=True,transparency=0.5,color=rgb_color(1,0.2,0))
start_display()
